package com;

import com.map.SortMap;
import com.model.Number;
import com.reduce.SortReduce;
import org.apache.hadoop.io.NullWritable;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * @author 10377
 */
@SpringBootApplication
public class Sorted {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        // TODO Auto-generated method stub
        // 创建job对象
        Job job = Job.getInstance(new Configuration());
        // 指定程序的入口
        job.setJarByClass(Sorted.class);

        // 指定自定义的Mapper阶段的任务处理类
        job.setMapperClass(SortMap.class);
        job.setMapOutputKeyClass(Number.class);
        job.setMapOutputValueClass(NullWritable.class);
        // 输入路径
        FileInputFormat.setInputPaths(job,new Path(args[0]));

        // 指定自定义的Reducer阶段的任务处理类
        job.setReducerClass(SortReduce.class);
        // 设置最后输出结果的Key和Value的类型
        job.setOutputKeyClass(Number.class);
        job.setOutputValueClass(NullWritable.class);
        // 将计算的结果输出
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        // 执行提交job方法，直到完成，参数true打印进度和详情
        boolean flag = job.waitForCompletion(true);
        System.exit(flag?0:1);
    }
}
